using System;
using System.Collections.Generic;
using FunctionInterface;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace Functions
{
	/// <summary>
	/// 发送信息.
	/// </summary>
	[Activity (Label = "LaunchPhoneDialer", MainLauncher = true)]
	public class SendMessage : Activity, IProcessCommand
	{
		public event OutputMessageEventHandler OutputMessage;
		public FunctionInterface.Context Context {get; set;}
		
		public SendMessage ()
		{
		}
		
		public List<string> GetCommnads ()
		{
			List<string> cms = new List<string>();
			cms.Add("-s 发送短信");
			return cms;
		}
		
		public void Process (string command)
		{
			string[] strs = command.Split(' ');
			Send(strs[0], strs[1]);
			if(OutputMessage != null)
			{
				OutputMessage(this, new OutputMessageEventArgs(){ Message = "短信发送成功。"});
			}
		}
		
		public bool Validate (string command)
		{
			return true;
		}
		
		/// <summary>
		/// 发送信息
		/// </summary>
		/// <param name='phoneNo'>
		/// Phnone no.
		/// </param>
		/// <param name='message'>
		/// Message.
		/// </param>
		public void Send(string phoneNo, string message)
		{
			Android.Telephony.SmsManager sm = Android.Telephony.SmsManager.Default;  
        	//PendingIntent pi = PendingIntent.GetBroadcast(null, 0, new Intent(), PendingIntentFlags.NoCreate);  
        	sm.SendTextMessage(phoneNo, null, message, null, null);  
		}
	}
}

// 您有新信息
//    NotificationManager nm;  
//    protected override void OnCreate(Bundle bundle)  
//    {  
//        base.OnCreate(bundle);  
//        SetContentView(Resource.Layout.Main);  
//        try  
//        {  
//            nm = this.GetSystemService(Service.NotificationService) as NotificationManager;  
//            Spinner mySpinner = FindViewById<Spinner>(Resource.Id.mySpinnner);  
//            ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerItem, new string[] { "显示图标1", "显示图标2", "显示图标3", "显示图标4", "关闭显示" });  
//            mySpinner.Adapter = adapter;  
//            mySpinner.ItemSelected += (sender, e) =>  
//            {  
//                switch (e.Position)  
//                {  
//                    case 0:  
//                        Notify(Resource.Drawable.btn1, "通知1");  
//                        break;  
//                    case 1:  
//                        Notify(Resource.Drawable.btn2, "通知2");  
//                        break;  
//                    case 2:  
//                        Notify(Resource.Drawable.btn3, "通知3");  
//                        break;  
//                    case 3:  
//                        Notify(Resource.Drawable.btn4, "通知4");  
//                        break;  
//                    case 4:  
//                        nm.Cancel(0);  
//                        break;  
//                }  
//            };  
//        }  
//        catch (System.Exception ex)  
//        {  
//            MessageBox.ShowErrorMessage(this, ex);  
//        }  
//    }  
//    private void Notify(int iconId, string text)  
//    {  
//        Activity2 act2 = new Activity2();  
//        Intent notifyIntent = new Intent(this, act2.Class);  
//        notifyIntent.SetFlags(ActivityFlags.NewTask);  
//        PendingIntent appIntent = PendingIntent.GetActivity(this, 0, notifyIntent, 0);  
//        Notification n = new Notification  
//        {  
//            Icon = iconId,  
//            TickerText = new Java.Lang.String(text),  
//            Defaults = NotificationDefaults.Sound,  
//        };  
//        n.SetLatestEventInfo(this, "通知", text, appIntent);  
//        nm.Notify(0, n);  
//    }  
//
